home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / ai.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  9.4 KB  |  418 lines

  1. /*
  2.  * $Id: ai.trm,v 1.10 1995/12/20 21:47:38 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - ai.trm */
  7. /*
  8.  * Copyright (C) 1991, 1992   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *     aifm
  26.  *
  27.  * AUTHORS
  28.  *  Ray Ghanbari
  29.  * 
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  *
  32.  * The 'aifm' driver produces files editable by Adobe Illustrator 3.0
  33.  * To change font to Courier and font size to 20pts use 
  34.  * 'set term aifm "Courier" 20'.
  35.  * To switch to color output use
  36.  * 'set term aifm color'.
  37.  */
  38.  
  39.  /* AIFM driver by Ray Ghanbari, ray@mtl.mit.edu, 
  40.  *    based on PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
  41. /* Changed to 3.6 terminal format, David C. Schooley, 9/29/95 */
  42.  
  43. #ifndef GOT_DRIVER_H
  44. #include "driver.h"
  45. #endif
  46.  
  47. #ifdef TERM_REGISTER
  48. register_term(aifm)
  49. #endif
  50.  
  51. #ifdef TERM_PROTO
  52. TERM_PUBLIC void AI_init __P((void));
  53. TERM_PUBLIC void AI_graphics __P((void));
  54. TERM_PUBLIC void AI_text __P((void));
  55. TERM_PUBLIC void AI_linetype __P((int linetype));
  56. TERM_PUBLIC void AI_move __P((unsigned int x, unsigned int y));
  57. TERM_PUBLIC void AI_vector __P((unsigned int x, unsigned int y));
  58. TERM_PUBLIC void AI_put_text __P((unsigned int x, unsigned int y, char *str));
  59. TERM_PUBLIC int AI_text_angle __P((int ang));
  60. TERM_PUBLIC void AI_reset __P((void));
  61. TERM_PUBLIC void AI_options __P((void));
  62. TERM_PUBLIC int AI_justify_text __P((enum JUSTIFY mode));
  63.  
  64. #define AI_XOFF    50    /* page offset in pts */
  65. #define AI_YOFF    50
  66.  
  67. #define AI_XMAX 5000
  68. #define AI_YMAX 3500
  69.  
  70. #define AI_XLAST (AI_XMAX - 1)
  71. #define AI_YLAST (AI_YMAX - 1)
  72.  
  73. #define AI_VTIC (AI_YMAX/80)
  74. #define AI_HTIC (AI_YMAX/80)
  75.  
  76. #define AI_SC (10.0)                /* scale is 1pt = 10 units */
  77. #define AI_LW (0.5*AI_SC)        /* linewidth = 0.5 pts */
  78.  
  79. #define AI_VCHAR (14*AI_SC)        /* default is 14 point characters */
  80. #define AI_HCHAR (14*AI_SC*6/10)
  81.  
  82. #endif
  83.  
  84.  
  85.  
  86. #ifndef TERM_PROTO_ONLY
  87. #ifdef TERM_BODY
  88.  
  89. char ai_font[MAX_ID_LEN+1] = "Times-Roman" ; /* name of font */
  90. int ai_fontsize = 14;                     /* size of font in pts */
  91. TBOOLEAN ai_color = FALSE;
  92. TBOOLEAN ai_stroke = FALSE;
  93. int ai_page=0;            /* page count */
  94. int ai_path_count=0;     /* count of lines in path */
  95. int ai_ang=0;            /* text angle */
  96. enum JUSTIFY ai_justify=LEFT;    /* text is flush left */
  97.  
  98.  
  99. void AI_options()
  100. {
  101.     if (!END_OF_COMMAND) {
  102.         if (almost_equals(c_token,"d$efault")) {
  103.             ai_color=FALSE;
  104.             strcpy(ai_font,"Times-Roman");
  105.             ai_fontsize = 14;
  106.             c_token++;
  107.         }
  108.     }
  109.  
  110.     if (!END_OF_COMMAND) {
  111.         if (almost_equals(c_token,"m$onochrome")) {
  112.             ai_color=FALSE;
  113.             c_token++;
  114.         }
  115.         else if (almost_equals(c_token,"c$olor")) {
  116.             ai_color=TRUE;
  117.             c_token++;
  118.         }
  119.     }
  120.  
  121.     if (!END_OF_COMMAND && isstring(c_token)) {
  122.         quote_str(ai_font,c_token, MAX_ID_LEN);
  123.         c_token++;
  124.     }
  125.  
  126.     if (!END_OF_COMMAND) {
  127.         /* We have font size specified */
  128.         struct value a;
  129.         ai_fontsize = (int)real(const_express(&a));
  130.         c_token++;
  131.         term->v_char = (unsigned int)(ai_fontsize*AI_SC);
  132.         term->h_char = (unsigned int)(ai_fontsize*AI_SC*6/10);
  133.     }
  134.  
  135.     sprintf(term_options,"%s \"%s\" %d",
  136.         ai_color ? "color" : "monochrome",ai_font,ai_fontsize);
  137. }
  138.  
  139.  
  140. void AI_init()
  141. {
  142.     ai_page = 0;
  143.     fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-1.2\n");
  144.     fprintf(outfile,"%%%%BoundingBox: %d %d %d %d\n", AI_XOFF,AI_YOFF,
  145.         (int)((AI_XMAX)/AI_SC+0.5+AI_XOFF), 
  146.         (int)((AI_YMAX)/AI_SC+0.5+AI_YOFF) );
  147.     fprintf(outfile,"%%%%Template:\n");
  148.     fprintf(outfile,"%%%%EndComments\n");
  149.     fprintf(outfile,"%%%%EndProlog\n");
  150. }
  151.  
  152.  
  153. void AI_graphics()
  154. {
  155.     ai_page++;
  156. /*    fprintf(outfile,"%%%%Page: %d %d\n",ai_page,ai_page);*/
  157.     fprintf(outfile,"0 G\n");
  158.     fprintf(outfile,"1 j\n");
  159.     fprintf(outfile,"1 J\n");
  160.     fprintf(outfile,"u\n");
  161.     ai_path_count = 0;
  162.     ai_stroke = FALSE;
  163. }
  164.  
  165.  
  166. void AI_text()
  167. {
  168.     if (ai_stroke) {
  169.         fprintf(outfile,"S\n");
  170.         ai_stroke = FALSE;
  171.     }
  172.     fprintf(outfile,"U\n");
  173.     ai_path_count = 0;
  174. }
  175.  
  176.  
  177. void AI_reset()
  178. {
  179.     fprintf(outfile,"%%%%Trailer\n");
  180. /*    fprintf(outfile,"%%%%Pages: %d\n",ai_page);*/
  181. }
  182.  
  183.  
  184. void AI_linetype(linetype)
  185. int linetype;
  186. {
  187.     if (ai_stroke) {
  188.         fprintf(outfile,"S\n");
  189.         ai_stroke = FALSE;
  190.     }
  191.     switch(linetype) {
  192.         case -2 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC*2.0);
  193.                 if (ai_color) {
  194.                     fprintf(outfile,"0 0 0 1 K\n");
  195.                 }
  196.                 else {                
  197.                     fprintf(outfile,"[] 0 d\n");
  198.                 }
  199.                 break;
  200.                 
  201.         case -1 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC/2.0);
  202.                 if (ai_color) {
  203.                     fprintf(outfile,"0 0 0 1 K\n");
  204.                 }
  205.                 else {                
  206.                     fprintf(outfile,"[1 2] 0 d\n");
  207.                 }
  208.                 break;
  209.                 
  210.         case 0 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  211.                 if (ai_color) {
  212.                     fprintf(outfile,"1 0 1 0 K\n");
  213.                 }
  214.                 else {                
  215.                     fprintf(outfile,"[] 0 d\n");
  216.                 }
  217.                 break;
  218.                 
  219.         case 1 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  220.                 if (ai_color) {
  221.                     fprintf(outfile,"1 1 0 0 K\n");
  222.                 }
  223.                 else {                
  224.                     fprintf(outfile,"[4 2] 0 d\n");
  225.                 }
  226.                 break;
  227.                 
  228.         case 2 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  229.                 if (ai_color) {
  230.                     fprintf(outfile,"0 1 1 0 K\n");
  231.                 }
  232.                 else {                
  233.                     fprintf(outfile,"[2 3] 0 d\n");
  234.                 }
  235.                 break;
  236.                 
  237.         case 3 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  238.                 if (ai_color) {
  239.                     fprintf(outfile,"0 1 0 0 K\n");
  240.                 }
  241.                 else {                
  242.                     fprintf(outfile,"[1 1.5] 0 d\n");
  243.                 }
  244.                 break;
  245.                 
  246.         case 4 :  fprintf(outfile,"%f w\n",AI_LW/AI_SC);
  247.                 if (ai_color) {
  248.                     fprintf(outfile,"1 0 0 0 K\n");
  249.                 }
  250.                 else {                
  251.                     fprintf(outfile,"[5 2 1 2] 0 d\n");
  252.                 }
  253.                 break;
  254.                 
  255.         case 5 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  256.                 if (ai_color) {
  257.                     fprintf(outfile,"0 0 1 0 K\n");
  258.                 }
  259.                 else {                
  260.                     fprintf(outfile,"[4 3 1 3] 0 d\n");
  261.                 }
  262.                 break;
  263.                 
  264.         case 6 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  265.                 if (ai_color) {
  266.                     fprintf(outfile,"0 0 0 1 K\n");
  267.                 }
  268.                 else {                
  269.                     fprintf(outfile,"[2 2 2 4] 0 d\n");
  270.                 }
  271.                 break;
  272.                 
  273.         case 7 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  274.                 if (ai_color) {
  275.                     fprintf(outfile,"0 0.7 1 0 K\n");
  276.                 }
  277.                 else {                
  278.                     fprintf(outfile,"[2 2 2 2 2 4] 0 d\n");
  279.                 }
  280.                 break;
  281.                 
  282.         case 8 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  283.                 if (ai_color) {
  284.                     fprintf(outfile,"0.5 0.5 0.5 0 K\n");
  285.                 }
  286.                 else {                
  287.                     fprintf(outfile,"[2 2 2 2 2 2 2 4] 0 d\n");
  288.                 }
  289.                 break;
  290.         }
  291.                 
  292.     ai_path_count = 0;
  293. }
  294.  
  295.  
  296. void AI_move(x,y)
  297. unsigned int x,y;
  298. {
  299.     if (ai_stroke) fprintf(outfile,"S\n");
  300.     fprintf(outfile,"%.2f %.2f m\n", x/AI_SC, y/AI_SC);
  301.     ai_path_count += 1;
  302.     ai_stroke = TRUE;
  303. }
  304.  
  305.  
  306. void AI_vector(x,y)
  307. unsigned int x,y;
  308. {
  309.     fprintf(outfile,"%.2f %.2f l\n", x/AI_SC, y/AI_SC);
  310.     ai_path_count += 1;
  311.     ai_stroke = TRUE;
  312.     if (ai_path_count >= 400) {
  313.         fprintf(outfile,"S\n%.2f %.2f m\n",x/AI_SC,y/AI_SC);
  314.         ai_path_count = 0;
  315.     }
  316. }
  317.  
  318.  
  319. void AI_put_text(x,y,str)
  320. unsigned int x, y;
  321. char *str;
  322. {
  323. char ch;
  324.     if (ai_stroke) {
  325.         fprintf(outfile,"S\n");
  326.         ai_stroke = FALSE;
  327.     }
  328.     switch(ai_justify) {
  329.         case LEFT :   fprintf(outfile,"/_%s %d 0 0 0 z\n",ai_font,ai_fontsize);
  330.             break;
  331.         case CENTRE : fprintf(outfile,"/_%s %d 0 0 1 z\n",ai_font,ai_fontsize);
  332.             break;
  333.         case RIGHT :  fprintf(outfile,"/_%s %d 0 0 2 z\n",ai_font,ai_fontsize);
  334.             break;
  335.     }
  336.     if (ai_ang==0) {
  337.         fprintf(outfile,"[ 1 0 0 1 %.2f %.2f] e\n",
  338.             x/AI_SC,y/AI_SC - ai_fontsize/3.0);
  339.     }
  340.     else {
  341.         fprintf(outfile,"[ 0 1 -1 0 %.2f %.2f] e\n",
  342.             x/AI_SC - ai_fontsize/3.0,y/AI_SC);
  343.     }
  344.         
  345.     putc('(',outfile);
  346.     ch = *str++;
  347.     while(ch!='\0') {
  348.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  349.             putc('\\',outfile);
  350.         putc(ch,outfile);
  351.         ch = *str++;
  352.     }
  353.     fprintf(outfile,") t\nT\n");
  354.     ai_path_count = 0;
  355. }
  356.  
  357. int AI_text_angle(ang)
  358. int ang;
  359. {
  360.     ai_ang=ang;
  361.     return TRUE;
  362. }
  363.  
  364. int AI_justify_text(mode)
  365. enum JUSTIFY mode;
  366. {
  367.     ai_justify=mode;
  368.     return TRUE;
  369. }
  370.  
  371. #endif
  372.  
  373.  
  374. #ifdef TERM_TABLE
  375.  
  376. TERM_TABLE_START(aifm_driver)
  377.  
  378.          "aifm", "Adobe Illustrator 3.0 Format",
  379.        AI_XMAX, AI_YMAX, AI_VCHAR, AI_HCHAR, 
  380.        AI_VTIC, AI_HTIC, AI_options, AI_init, AI_reset, 
  381.        AI_text, null_scale, AI_graphics, AI_move, AI_vector, 
  382.        AI_linetype, AI_put_text, AI_text_angle, 
  383.        AI_justify_text, do_point, do_arrow, set_font_null}
  384.  
  385. #undef LAST_TERM
  386. #define LAST_TERM aifm_driver
  387. #endif
  388. #endif /* TERM_PROTO_ONLY */
  389.  
  390.  
  391. #ifdef TERM_HELP
  392. START_HELP(aifm)
  393. "1 aifm",
  394. "?set terminal aifm",
  395. "?aifm",
  396. " Several options may be set in the Adobe Illustrator 3.0 driver.",
  397. "",
  398. " Syntax:",
  399. "         set terminal aifm {<color>}",
  400. "                                 {\"<fontname>\"} {<fontsize>}",
  401. "",
  402. " <color> is either `color` or `monochrome`; \"<fontname>\" is the name of a",
  403. " valid PostScript font; <fontsize> is the size of the font in PostScript",
  404. " points, before scaling by the `set size` command.  Selecting `default` sets",
  405. " all options to their default values: `monochrome`, \"Helvetica\", and 14pt.",
  406. " Also, since AI does not really support multiple pages, multiple graphs will",
  407. " be output directly on top of one another.  However, each graph will be",
  408. " grouped individually, making it easy to separate them inside AI (just pick",
  409. " them up and move them).",
  410. "",
  411. " Examples:",
  412. "         set term aifm",
  413. "         set term aifm 22",
  414. "         set size 0.7,1.4",
  415. "         set term aifm color \"Times-Roman\" 14"
  416. END_HELP(aifm)
  417. #endif
  418.